<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/common.css"/>
		<link rel="stylesheet" type="text/css" href="../css/article_list.css"/>
	</head>
	<body>
		<form action="" method="post" class="search_box">
			<span>标题：<input type="text" id="title" name="title"/></span>

			<button type="button" class="sub">搜索</button>
		</form>
		<div id="list_content">

		</div>

		<div class="tcdPageCode"></div>
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="../layui/layui.js"></script>
		<script src="../js/jquery.page.js" type="text/javascript" charset="utf-8"></script>
		<script>
			jQuery.browser = {};
			(function() {
				jQuery.browser.msie = false;
				jQuery.browser.version = 0;
				if(navigator.userAgent.match(/MSIE ([0-9]+)./)) {
					jQuery.browser.msie = true;
					jQuery.browser.version = RegExp.$1;
				}
			})();

			var params = {
				name:'', //姓名
				mobile: '', //手机号
				cert: '', //执业证号
				expert: '', //领域
				limit: 10, //记录数
				offset: 1 //页码
			};
			$(document).ready(function() {

				search();//搜索

					//绑定搜索事件
					$(".sub").click(function() {
						params.title = $("#title").val();
						search();
					});

			});
			//删除方法
			function del(id) {
				$.ajax({
					url: '/user/content/' + id,
					type: 'delete',
					dataType: "json",
					success: function(data) {
						if(data.rel) {
							layui.use('layer', function() {
								var layer = layui.layer;
								layer.msg('删除成功', {
									icon: 6
								})
							})
							search();
						}
					}
				});
			}
			//查询方法
			function search() {

				$.ajax({
					url: '/user/content/list',
					type: 'get',
					data: params,
					dataType: "json",
					success: function(data) {
						var headTable = "<table border='0' cellspacing='0' cellpadding='0'><tr><th>ID</th><th>缩略图</th><th style='text-align: left;'>标题</th>" +
							"<th>发布时间</th><th>操作</th></tr>";
						var contentHtml = "";
						if(data.rows) {
							var reg = new RegExp(",", "g");
							for(var i = 0; i < data.rows.length; i++) {
								var obj = data.rows[i];
								var index = i + 1;
								var imgHtml = "";
								if(obj.image) {
									imgHtml = "<img src='" + obj.image + "'/>";
								} else {
									imgHtml = "暂无图片";
								}
								contentHtml += "<tr><td>" + obj.id + "</td><td>" + imgHtml + "</td>" +
									"<td  style='text-align: left;'>" + obj.title + "</td>"+
									"<td>	"+obj.crtTime+"1</td> " +
									"<td><button id='" + obj.id + "' class='del'>删除</button></td>	</tr>";
							}
						} else {
							contentHtml = "<tr><td colspan='5'>暂无记录</td></tr>";
						}

						$("#list_content").html(headTable + contentHtml + "</table>");
						//绑定删除事件
						$(".del").click(function() {

							var id = $(this).attr("id");
							layui.use('layer', function() {
								var layer = layui.layer;
								layer.confirm('确认删除此信息', {icon: 3},function(index){
									layer.close(index)
									del(id);
								},function(index){
									layer.close(index)
								})
							})
							/*if(confirm("确认删除此信息？")){
									del($(this).attr("id"));
							}*/
						});
						$(".tcdPageCode").createPage({
							pageCount: data.totalPages,
							current: data.page,
							backFn: function(p) {
								//console.log(p);
								params.offset = p;
								search();
							}
						});
					}
				});
			}

			document.onkeydown = function(event){
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if(e && e.keyCode == 116){
					event.preventDefault();

					$(window.parent.$('.showIframe').each(function(){
						if(!$(this).hasClass('hideIframe')){
							$(this).children('iframe').attr('src',$(this).children('iframe').attr('src'))
						}
					}))
				}
			}
		</script>
	</body>
</html>
